package org.jasper.impl.parse;

import org.jasper.api.model.PomModel;
import org.xml.sax.helpers.DefaultHandler;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.InputStream;

/**
 * Created by OP038074 on 2018/7/26.
 */
public class MinimalPomParser extends DefaultHandler {

    private PomModel.InternalModel model;

    public static PomModel parse(String path, InputStream is) {
        MinimalPomParser handler = new MinimalPomParser();
        try {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setValidating( false );
            factory.setNamespaceAware( false );

            SAXParser parser = factory.newSAXParser();
            parser.parse( is, handler );
        } catch (Exception e) {
            throw new RuntimeException("Unable to parse File '" + path + "'", e);
        }

        return handler.getPomModel();
    }

    public PomModel getPomModel() {
        return this.model;
    }
}
